<!doctype html>
<html lang="en" data-bs-theme="auto">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <title>图片轮播</title>

  <link href="/assets/dist/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/assets/icons/font/bootstrap-icons.css">
  <link rel="stylesheet" href="/libs/tree/select-tree.css">
 
  <link href="/css/dashboard.css" rel="stylesheet">
  <script src="/js/jquery.min.js"></script>
  <script src="/libs/tree/select-tree.js"></script>
</head>

<body>

  <div class="container">
    <form class="g-3 mt-1" id="form" method="post">
      <h3>图片轮播</h3>
      <div class="row">
        <div class="col-md-6">
          <label for="title" class="form-label">模块名称</label>
          <input type="text" class="form-control" id="title" name="title" value="<% echo<<obj["info"]["title"].to_string(); %>">
        </div>
      </div>  
    
      <div class="row">
        <%c for(auto &a:obj["infotopimgs"].as_array()){ %>
          <div class="row g-3 mt-1">
                <div class="col-md-2">
                <input type="text" class="form-control"  name="header_title[]" placeholder="头图标题" value="<% echo<<a.second["header_title"].to_string(); %>">
              </div>
              <div class="col-md-2">
                <input type="text" class="form-control"  name="header_content[]"  placeholder="头图说明" value="<% echo<<a.second["header_content"].to_string(); %>">
              </div>
              <div class="col-md-6">
                <div class="input-group row">
                  <input type="file" class="form-control uploadfile col-md-4"  accept=".jpg,.png,.jpeg"  aria-describedby="inputGroupFileAddon04" aria-label="Upload">
                  <input type="text" class="form-control col-md-8"  name="header_urlpath[]"  placeholder="图片地址" value="<% echo<<a.second["header_urlpath"].to_string(); %>">
                </div>
              </div>
              <div class="col-md-2">
                 <button type="button" class="btn btn-outline-info" onclick="additem(this)">+</button>
                 <button type="button" class="btn btn-outline-danger" onclick="removeitem(this)">-</button>
              </div>
          </div>
           <%c } %> 
           <%c if(obj["infotopimgs"].size()==0){ %>
          <div class="row g-3 mt-1">
                <div class="col-md-2">
                <input type="text" class="form-control"  name="header_title[]" placeholder="头图标题" value="">
              </div>
              <div class="col-md-2">
                <input type="text" class="form-control"  name="header_content[]"  placeholder="头图说明" value="">
              </div>
              <div class="col-md-6">
                <div class="input-group row">
                  <input type="file" class="form-control uploadfile col-md-4"  accept=".jpg,.png,.jpeg"  aria-describedby="inputGroupFileAddon04" aria-label="Upload">
                  <input type="text" class="form-control col-md-8"  name="header_urlpath[]"  placeholder="图片地址" value="">
                </div>
              </div>
              <div class="col-md-2">
                 <button type="button" class="btn btn-outline-info" onclick="additem(this)">+</button>
                 <button type="button" class="btn btn-outline-danger" onclick="removeitem(this)">-</button>
              </div>
          </div>
           <%c } %> 
      </div>  
       
      <div class="row" style="margin-top: 20px;">
        <div class="col-md-6">
        <br />
        <input type="hidden" name="hbid" value="<% echo<<obj["info"]["hbid"].to_string(); %>">
        <input type="hidden" name="viewtype" value="1">
        <button type="submit" class="btn btn-primary">编辑</button>
        <a href="/admin/marhome" class="btn btn-link rounded-pill px-3">返回</a>
        </div>
      </div>
    </form>

  </div>
  
 
 
<div class="modal fade" id="myfiletobigModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="staticBackdropLabel">提示</h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
         文件太大了，请传4M以下的文件！
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
         
      </div>
    </div>
  </div>
</div> 

  
  <script src="/assets/dist/js/bootstrap.bundle.min.js"></script>
  <script lang="javascript">

     function gotourl()
    {
        window.location.href='/admin/marhome';
    }
    $("#form").on("submit", function (event) {
      event.preventDefault();
      var data = $(this).serialize();

      var obj=this;  
      //得到序列化数据
      $.ajax({
        url: "/admin/edithomeblockpost",
        method: 'post',
        contentType:"application/x-www-form-urlencoded",
        data: data,
        dataType: "json"
        }).done(function(data) {
          if(data.code==0)
          {
             setTimeout("gotourl()",500 );  
          }
        });
    });
    function additem(obj)
    {
        jQuery(obj).parent().parent().after(jQuery(obj).parent().parent().clone()); 
        upfile_event();
    }
    function removeitem(obj)
    {
        if(jQuery(obj).parent().parent().parent().children().length>1)
        {
           jQuery(obj).parent().parent().remove();      
        }
        
    }
    
  
  function upfile_event()
    {

      $(".uploadfile").change(function(){
              var fd=new FormData();
              if($(this).get(0).files[0].size>15728640){
                alert("附件不能大于15M，附件为zip、rar、jpg格式！");
                return false;
              }
              fd.append("upfile",$(this).get(0).files[0]);
              var selfobj=this;
              $.ajax({
                url:"/admin/topicfileupload?action=uploadimage",
                type:"POST",
                processData: false,
                contentType:false,
                data: fd,
                dataType: "json",
                success:function(data){
                    if(data.state=="SUCCESS"){
                      $(selfobj).next().val(data.url);
                    }
                    else
                    {
                        alert(data.state);
                    }
                    //console.log(data.status);
                }
              });
            });
    }

    $(document).ready(function(e) {
         
            
             $(".uploadfile").change(function(){
              var fd=new FormData();
              if($(this).get(0).files[0].size>15728640){
                alert("附件不能大于15M，附件为zip、rar、jpg格式！");
                return false;
              }
              fd.append("upfile",$(this).get(0).files[0]);
              var selfobj=this;
              $.ajax({
                url:"/admin/topicfileupload?action=uploadimage",
                type:"POST",
                processData: false,
                contentType:false,
                data: fd,
                dataType: "json",
                success:function(data){
                    if(data.state=="SUCCESS"){
                      $(selfobj).next().val(data.url);
                    }
                    else
                    {
                        alert(data.state);
                    }
                    //console.log(data.status);
                }
              });
            });

 
    });
  </script>
</body>

</html>